package com.hellobike.haxing.modules.shop.service.impl;

import com.hellobike.haxing.modules.shop.entity.ShopAccount;
import com.hellobike.haxing.modules.shop.mapper.ShopAccountMapper;
import com.hellobike.haxing.modules.shop.mapper.ShopMapper;
import com.hellobike.haxing.modules.shop.service.IShopAccountService;
import com.hellobike.haxing.modules.shop.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;

/**
 * @Description: 提货点账单
 * @Author: haxing-boot
 * @Date:   2020-02-08
 * @Version: V1.0
 */
@Service
public class ShopAccountServiceImpl extends ServiceImpl<ShopAccountMapper, ShopAccount> implements IShopAccountService {
    @Autowired
    private IShopService shopService;
    @Autowired
    private ShopAccountMapper shopAccountMapper;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void addIncome(Long shopId,BigDecimal amount,Integer status, String reason) {
        shopService.updateIncome(amount,shopId);
        ShopAccount shopAccount = new ShopAccount();
        shopAccount.setAmount(amount);
        shopAccount.setShopId(shopId);
        shopAccount.setStatus(status);
        shopAccount.setType(1);
        shopAccount.setReason(reason);
        super.save(shopAccount);
    }

    @Override
    public void updateRejectSubStatus(Long applyId) {
        shopAccountMapper.updateSubStatus(applyId,2);
    }

    @Override
    public void updateWithSuccessSubStatus(Long applyId) {
        shopAccountMapper.updateSubStatus(applyId,3);
    }
}
